package com.lan.test01;

import com.lan.domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test05 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //1.获取Class对象
        Class clazz = Class.forName("com.lan.domain.Student");

        //2. 获取构造方法对象
        Constructor constructor = clazz.getDeclaredConstructor(String.class, Integer.class);

        //3.取消访问检查
        constructor.setAccessible(true);

        //4.创建对象
        Student stu = (Student) constructor.newInstance("张三", 12);

        System.out.println(stu);

        //创建空参的简写格式
        Student stu1 = (Student) clazz.newInstance();
        System.out.println(stu1);
    }
}
